import os import sys from os import listdir from os.path import isfile, isdir, join startpath = os.getcwd() out = open(startpath + '\\index.htm', 'w') prefixIn = open(startpath + '\\prefix.txt') postfixIn = open(startpath + "\\postfix.txt") out.write(prefixIn.read()) spacesPerIndent = 10 def addNBSP(depth): for folderIndentationIndex in range (0,depth * spacesPerIndent): out.write(' ') def buildFileLinksForFolderStructure(currentPath, currentFolder, depth): print(currentPath) currentFiles = [ f for f in listdir(currentPath) if isfile(join(currentPath,f)) ] currentDirs = [ f for f in listdir(currentPath) if isdir(join(currentPath,f)) ] id = currentPath.replace(startpath,"").replace("\\","") if currentPath == startpath: id = "root" addNBSP(depth) out.write('' + currentFolder + '
\n') out.write ('
\n') def beginBuildFileLinksForFolderStructure(currentPath): currentDirs = [ f for f in listdir(currentPath) if isdir(join(currentPath,f)) ] for folder in currentDirs: buildFileLinksForFolderStructure(currentPath + "\\" + folder, folder, 0) beginBuildFileLinksForFolderStructure(startpath) out.write(postfixIn.read())